package com.huarui.saleOrder.service;

import java.util.Map;

import com.huarui.purchaseOrder.model.PurOrSaleOrder;
import com.huarui.saleOrder.enums.SaleOrderFunctionEnum;
import com.huarui.saleOrder.enums.SaleOrderOperateMesEnum;
import com.huarui.user.model.SessionMessage;
import com.huarui.user.security.UserHolder;

public class SaleOrderServiceUtil {
	public static final String ALERTMES = "sale_alert_mes";
	
	public static final String ORDERSID = "saleOrderId";
	
	public static final String STATUS = "status";
	
	public static final String REMOVE = "remove";
	
	public static final String FUNC = "loadedMesesKeys";
	
	public static final String REMOVE_YES = "1";
	
	public static final void toShowOrders(Map<String, Object> mesMap, PurOrSaleOrder orders) {
		
		SessionMessage se = UserHolder.getCurrentSessionMessage();
		Integer userId = se.getUserId();
		
		if(orders == null) {
			mesMap.put(ALERTMES, SaleOrderOperateMesEnum.ORDERS_NOT_EXIST.getKey());
			mesMap.put(REMOVE, REMOVE_YES);
			mesMap.put(FUNC, SaleOrderFunctionEnum.CALLBACK_ALERT_FUNC.getKey());
		} else {
			if(PurOrSaleOrder.STATUS_TMP.equals(orders.getStatus())
					|| PurOrSaleOrder.STATUS_WAIT_SELLER_ACPT.equals(orders.getStatus())) {
				if( !userId.equals(orders.getCurrentorId())) {
					mesMap.put(STATUS, orders.getStatus() + "-");
//					mesMap.put(ALERTMES, SaleOrderOperateMesEnum.ORDERS_NOT_CURRENT_USER.getKey());
				} else {
					mesMap.put(STATUS, orders.getStatus());
//					mesMap.put(ALERTMES, SaleOrderOperateMesEnum.ORDERS_OK.getKey());
				}
			} else {
				mesMap.put(STATUS, orders.getStatus());
//				mesMap.put(ALERTMES, SaleOrderOperateMesEnum.ORDERS_OK.getKey());
			}
			mesMap.put(FUNC, SaleOrderFunctionEnum.LOAD_SALE_FORM.getKey()  + ":" 
							+ SaleOrderFunctionEnum.lOAD_DETAILS_GRID.getKey() + ":" 
							+ SaleOrderFunctionEnum.LOAD_BUTTONS_TOOL_BAR.getKey() );
			mesMap.put(ORDERSID, orders.getId());
			
			mesMap.put("codeOfSeller", orders.getCodeOfSeller());
		}
		
	}
	
}
